﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using BrainTechLLC.WPF;

namespace BrainTechLLC.ImageOperatorsNonAForgeDependent
{
    public class BasicBitmapPopulator
    {
        public virtual Bitmap Populate(BasicBitmap item, ICoreDataProvider dataProvider, string fileName, BasicByteArrayPopulator byteArrayPopulator = null)
        {
            if (byteArrayPopulator == null)
                byteArrayPopulator = new BasicByteArrayPopulator();

            byte[] byteArray = byteArrayPopulator.PopulateIfEmpty(item, dataProvider, fileName);
            Bitmap populated = byteArray.ReadBitmapFromByteStream();
            item.Bitmap = populated;
            item.BitmapWidth = populated == null ? 0 : populated.Width;
            item.BitmapHeight = populated == null ? 0 : populated.Height;
            return populated;
        }

        public virtual Bitmap PopulateIfEmpty(BasicBitmap item, ICoreDataProvider dataProvider, string fileName, BasicByteArrayPopulator byteArrayPopulator = null)
        {
            Bitmap populated = item.Bitmap;
            if (populated == null)
            {
                populated = Populate(item, dataProvider, fileName, byteArrayPopulator);
            }
            return populated;
        }
    }
}
